<template>
  <el-container class="blog_container">
    <el-header>
      <div>
        <img src="../../assets/鸡蛋.png" alt="" class="home_pic">
        <span>eggBlog</span>
      </div>
      <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect" active-text-color="#409EFF">
        <el-menu-item index="1" @click="tofirstPage">主页</el-menu-item>
        <el-menu-item index="2" @click="totype">分类</el-menu-item>
        <el-menu-item index="3" @click="toperson">个人中心</el-menu-item>
        <el-menu-item index="4" @click="tomanage">管理</el-menu-item>
      </el-menu>
      <div class="home_input">
        <el-col :span="20" push="100" >
          <!-- <el-input
            placeholder="SerchBlogs"
            v-model="inputTitle" class="selectT" @keyup.enter.native="search(inputTitle)">
            <i slot="prefix" class="el-input__icon el-icon-search" @click="search(inputTitle)"></i>
          </el-input> -->
          <a-input-search placeholder="SerchBlogs" style="width: 200px;" @search="search(inputTitle)" v-model="inputTitle"/>
        </el-col>
      </div>
      <div class="line"></div>
    </el-header>
    <el-aside class="aside" width="300px">
      <div>
        <strong>热门搜索</strong>
      </div>
      <div class="aside-tuijian">
        <a-list item-layout="horizontal" :data-source="data">
          <a-list-item slot="renderItem" key="item.title" slot-scope="item, index">
            <a-list-item-meta :description="item.type">
              <a slot="title" @click="toblog(item)" >{{ item.title }}</a>
              <a-avatar slot="avatar" :src="item.avatar" />
            </a-list-item-meta>
          </a-list-item>
        </a-list>
      </div>
    </el-aside>
    <el-main>
      <div class="serch-jieguo">
        <a-list item-layout="vertical" size="large" :pagination="pagination" :data-source="listData">
          <a-list-item slot="renderItem" key="item.title" slot-scope="item, index">
            <template v-for="{ type, text } in actions" slot="actions">
        <span :key="type">
          <a-icon :type="type" style="margin-right: 8px" />
          {{ text }}
        </span>
            </template>
            <img
              slot="extra"
              width="272"
              alt="logo"
              src="https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png"
            />
            <a-list-item-meta :description="item.description">
              <a slot="title" :href="item.href" @click="toblog(item)">{{ item.title }}</a>
              <a-avatar slot="avatar" :src="item.avatar" />
            </a-list-item-meta>
            <a @click="toblog(item)" class="article">{{ item.content }}</a>
          </a-list-item>
        </a-list>
      </div>
    </el-main>
  </el-container>

</template>

<script>
const listData = [];
// for (let i = 0; i < 23; i++) {
//   listData.push({
//     title: ``,
//     avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
//     type:
//       '',
//     content:
//       '',
//   });
// }
const data = [];
// for (let i = 0; i < 4; i++) {
//   data.push({
//     href: 'https://www.antdv.com/',
//     title: ``,
//     avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
//     type:'',
//     content:
//       '',
//   });
// }
export default {
  data(){
    return{
      inputTitle:'',
      data,
      listData,
      pagination: {
        onChange: page => {
          console.log(page);
        },
        pageSize: 5,
      },
      actions: [
        { type: 'star-o', text: '156' },
        { type: 'like-o', text: '156' },
        { type: 'message', text: '2' },
      ],
    }
  },
  created() {
    this.show()
  },
  methods:{
   async show(){
      var query = window.sessionStorage.getItem('query')
      const {data:res} = await this.$http.get('http://localhost:8081/blog/searchBlog',{params:{query:query}})
      const {data:res2} = await this.$http.get('http://localhost:8081/blog/hotblog')
      this.data = res2.data
      this.listData = res.data
    //  console.log(res.data)
     this.listData.sort(function(a,b){
   //降序
      //  return a.time < b.time ? 1 : -1
         return a.publishTime < b.publishTime ? 1 : -1
   });
    this.data.sort(function(a,b){
   //降序
      //  return a.time < b.time ? 1 : -1
         return a.publishTime < b.publishTime ? 1 : -1
   });
    },
    toblog(item){
      window.sessionStorage.setItem('number',item.number)
      this.$router.push('/blog2')
    },
    tofirstPage(){
     this.$router.push('/home')
    },
    totype(){
      this.$router.push('/type')
    },
     toperson(){
        if(window.sessionStorage.getItem('token')!=null||window.sessionStorage.getItem('admintoken')!=null)
        {
          this.$router.push('/infoside')
        }
        else{
           this.$message.warning('请先进行登陆')
            this.$router.push('/login')
        }
      },  
    tomanage(){
      if(window.sessionStorage.getItem('token')!=null)
      {
        this.$router.push('/list')
      }
      else if(window.sessionStorage.getItem('admintoken')!=null)
      {
        this.$router.push('/manage')
      }
      else{
        this.$message.warning('请先进行登陆')
        this.$router.push('/login')
      }
      },
    search(inputTitle){
      window.sessionStorage.setItem('query',inputTitle)
     this.show()
    },
  }
}
</script>
<style>
.el-main{
  background-color: #FFFFFF;
  width: 900px;
  height: 12000px;
  margin-left: 320PX;
  margin-top: -672px;
}
.el-menu-demo{
  margin-left: -9px;
}
.el-header{
  background-color:#FFFFFF;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  font-size: 20px;
}
.div{
  display: flex;
  align-items: center;}
span{
  margin-left: 15px;
}
.home_pic{
  height: 50px;
  width: 50px;
}
.home_input{
  text-align: right;
  display: flex;
  align-items: center;
}
.el-input__icon{
  display: flex;
  margin-left: -10px;
}
.blog_container{
  background-color: #F2F2F2;
  height: 100%;
  width: 100%;
}
.aside{
  background-color: #FFFFFF;
  margin-top: 10px;
}
</style>
